home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / DocShell / RlShell.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  16.9 KB  |  564 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        RlShell.h
  3.  
  4.     Contains:    definition of RealShell class
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1993 - 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <10>      1/8/97    DH        1401434: Added fields for keeping track of
  13.                                     different low-mem notifications.
  14.          <9>      10/22/96    DH        1378925: Discard orphan mouse-ups. 1336808
  15.                                     Allow user to resize document when it can't
  16.                                     be opened due to out-of-memory.
  17.          <8>    27.09.1996    NP        1385775: Incorrect dialog after OD
  18.                                     initialization fails.
  19.          <7>     6/21/96    CSL        1341242: Shouldn't be able to activate
  20.                                     windows w/modal dialog up
  21.          <6>     6/20/96    JP        1339269: Made quit handle the saving
  22.                                     parameter too
  23.          <5>     5/31/96    jpa        T10012: OpenFile takes forceOpenApp param,
  24.                                     returns document. Added dreaded Quit
  25.                                     command.
  26.          <4>    .03.1996    NP        1307182: Stuff for caching shell menu
  27.                                     items.
  28.          <3>    .03.1996    NP        1304875,1317218: Fix can't-cancel problem
  29.                                     on receipt of quit event.
  30.          <2>      3/1/96    JP        1314798: Added param to OpenAnotherFile
  31.  
  32.     To Do:
  33.     In Progress:
  34.         
  35. */
  36.  
  37.  
  38. #ifndef _RLSHELL_
  39. #define _RLSHELL_
  40.  
  41. #ifndef _PLFMDEF_
  42. #include "PlfmDef.h"
  43. #endif
  44.  
  45. #ifndef _ODTYPES_
  46. #include <ODTypes.h>
  47. #endif
  48.  
  49. #ifndef SOM_ODDraft_xh
  50. #include <Draft.xh>            /* for ODDraftPermissions */
  51. #endif
  52.  
  53. #ifndef _PLFMFILE_
  54. #include "PlfmFile.h"
  55. #endif
  56.  
  57. #ifndef _LINKLIST_
  58. #include <LinkList.h>
  59. #endif
  60.  
  61. #ifndef __PROCESSES__
  62. #include <Processes.h>        /* For ProcessSerialNumber */
  63. #endif
  64.  
  65. #ifndef __DIALOGS__
  66. #include <Dialogs.h>
  67. #endif
  68.  
  69.  
  70. //==============================================================================
  71. // Theory of Operation
  72. //==============================================================================
  73.  
  74. /*
  75.     The Shell contains all code which interfaces a particular platform's
  76.     user interface with the OpenDoc parts underneath.  
  77.     Each document is run in its own process.
  78.  
  79. */
  80.  
  81. //==============================================================================
  82. // Constants
  83. //==============================================================================
  84.  
  85.  
  86. //-------------------------------------------------------------------------------------
  87. // Menus
  88. //-------------------------------------------------------------------------------------
  89.  
  90. #define    kSHLMenuAbout    1
  91.  
  92. enum {
  93.     kSHLMenuNew            =    1
  94.     ,kSHLMenuOpen
  95.     ,kSHLMenuOpenDocument
  96.     ,kSHLMenuInsert
  97.     ,kSHLMenuClose
  98.     ,kSHLMenuDeleteDocument
  99.  
  100.     // menu separator
  101.  
  102.     ,kSHLMenuSave        =    8
  103.     ,kSHLMenuSaveACopy
  104.     ,kSHLMenuRevert
  105.     ,kSHLMenuDraft
  106.     ,kSHLMenuDocumentInfo
  107.     
  108.     // menu separator
  109.  
  110.     ,kSHLMenuPageSetup    =    14
  111.     ,kSHLMenuPrint
  112.     
  113. #ifdef SUPPORT_QUIT
  114.     // menu separator
  115.     
  116.     ,kSHLMenuQuit        =    17    /* Used only in APPL processes like CyberDog */
  117. #endif
  118. };
  119.  
  120.  
  121. enum {
  122.     kSHLMenuUndo        =    1
  123.     ,kSHLMenuRedo
  124.     
  125.     // menu separator
  126.  
  127.     ,kSHLMenuCut        =    4
  128.     ,kSHLMenuCopy
  129.     ,kSHLMenuPaste
  130.     ,kSHLMenuPasteAs
  131.     ,kSHLMenuClear
  132.     ,kSHLMenuSelectAll
  133.     
  134.     // menu separator
  135.  
  136.     ,kSHLMenuGetPartInfo=    11
  137.     ,kSHLMenuPreferences
  138.  
  139.     // menu separator
  140.  
  141.     ,kSHLMenuViewAsWin    =    14
  142. };
  143.  
  144.  
  145. //-------------------------------------------------------------------------------------
  146. // Dialogs
  147. //-------------------------------------------------------------------------------------
  148.  
  149. const ODSShort    kSHLscOK = 1;                        //OK button
  150. const ODSShort    kSHLscCancel = 2;                    //Cancel button
  151. const ODSShort    kSHLscNo = 3;                        //no, don't save
  152.  
  153. //==============================================================================
  154. // Scalar Types
  155. //==============================================================================
  156.  
  157. typedef    ODSShort    ODResNumber;
  158.  
  159. typedef struct {
  160.     UserItemUPP iconUPP;
  161.     ODBoolean makeStationery;
  162.     ODSession* session;
  163.     ODType changeKind;
  164.     ODType partKind;
  165.     ODTypeList* kindList;
  166. } SaveCopyStruct;
  167.  
  168. //==============================================================================
  169. // Classes defined in this interface
  170. //==============================================================================
  171.  
  172. class RealShell;
  173.  
  174. //==============================================================================
  175. // Classes used by this interface
  176. //==============================================================================
  177.  
  178. class ODSession;
  179. class ODDispatcher;
  180. class ODWindowState;
  181. class ODArbitrator;
  182. class ODDraft;
  183. class ODDocument;
  184. class ODContainer;
  185. class ODMenuBar;
  186. class ShellSI;
  187. class SIHelper;
  188. class PlatformFile;
  189. class StandardFileReply;
  190. class OrderedCollection;
  191. class ODAppleEvent;
  192. class ODDesc;
  193.  
  194. //==============================================================================
  195. // Functions defined in this interface
  196. //==============================================================================
  197.  
  198. void    CreateNewUntitledFile(PlatformFile* newFile); // newFile is in/out
  199.     // Will be moved to DocUtils. - TÇ
  200. void    GenericAlert( short alertID );
  201.  
  202. //==============================================================================
  203. // RealShell
  204. //==============================================================================
  205.  
  206. class RealShell
  207. {    
  208. public:
  209.  
  210. //-------------------------------------------------------------------------------------
  211. // Constructor/Destructor/Initialize/Shutdown/Go
  212. //-------------------------------------------------------------------------------------
  213.  
  214.     RealShell();
  215.     ODNVMethod ~RealShell();
  216.  
  217.     ODNVMethod void Initialize();    
  218.     ODNVMethod void InstallMenuBar();
  219.     ODNVMethod void InstallShellPlugIns(ODDraft* draft);
  220.     ODNVMethod void ScanShellPlugInsFldr(ODSShort fldrVRefNum, ODSLong fldrDirID,
  221.                                         ODDraft* draft);
  222.  
  223.     ODNVMethod void go();
  224.  
  225. //-------------------------------------------------------------------------------------
  226. // public for AppleEvent handlers, but private by convention
  227. //-------------------------------------------------------------------------------------
  228.  
  229.     //-------------------------------------------------------------------------------------
  230.     // Getters/Setters
  231.  
  232.     ODNVMethod ODSession* GetSession()    {return fSession;}    
  233.     ODNVMethod Environment* GetEV()    {return fEV;}    
  234.  
  235.     ODNVMethod void SetAEError(ODError error);
  236.  
  237.     //-------------------------------------------------------------------------------------
  238.     // Close
  239.  
  240.     ODNVMethod void            CloseWindow(ODPlatformWindow window,
  241.                                         DescType saveOptions);
  242.  
  243.     ODNVMethod ODBoolean    CloseDocument(ODDocument* document,
  244.                                             DescType saveOptions);
  245.     
  246.     ODNVMethod void            CloseAllDocs( DescType saveOptions );
  247.  
  248.  
  249.     //-------------------------------------------------------------------------------------
  250.     // Save
  251.  
  252.     ODNVMethod ODBoolean Save(ODDocument* document, 
  253.                                 ODBoolean isClosing = kODFalse, 
  254.                                 ODDescType saveOptions = kAEAsk);
  255.     // if it was a first save, and the user canceled, then it returns kODFalse.
  256.     // The second parameter is needed because if it is a first save in response to the (Save) button from the
  257.     // DontSave/Save/Cancel dialog, and if the user is saving to a different volume, then there is no need to
  258.     // reopen the document after closing and moving it to the new volume.
  259.     // The third parameter is needed because if the user requested that the file be closed and saved,
  260.     // he doesn't want a save dialog to appear
  261.  
  262. protected:
  263.  
  264.  
  265. //-------------------------------------------------------------------------------------
  266. // Event Dispatching
  267. //-------------------------------------------------------------------------------------
  268.     
  269.     ODNVMethod void         DispatchEvent(ODEventData* event);
  270.     ODNVMethod void         DispatchMouseDownEvent(ODEventData* event);
  271.     ODNVMethod void            DispatchMouseUpEvent(ODEventData* event);
  272.     ODNVMethod void         DispatchMenuEvent(ODEventData* event);
  273.     ODNVMethod void         DispatchKeyDownEvent(ODEventData* event);
  274.     
  275.     ODNVMethod void         HandleOSEvent(ODEventData* event);    
  276.     ODNVMethod void         HandleHighLevelEvent(ODEventData* event);
  277.     
  278.     ODNVMethod void            HandleMenuCommand(ODSLong menuResult, ODEventData* event);
  279.     ODNVMethod void         HandleMouseDownInWindow(WindowPtr window, ODSShort partcode, ODEventData* event);
  280.     ODNVMethod void            HandleMouseDownInCloseBox(WindowPtr window, ODEventData* event);
  281.     ODNVMethod void            HandleMouseDownInDragRegion(WindowPtr window, ODEventData* event);
  282.     ODNVMethod void            HandleMouseDownInGrowBox(WindowPtr window, ODEventData* event);
  283.     ODNVMethod void            HandleMouseDownInZoomBox(WindowPtr window, ODSShort partcode, ODEventData* event);
  284.  
  285.     ODNVMethod void            ExportClipboard(ODBoolean canAlert);
  286.     
  287.     ODNVMethod ODBoolean    CheckFileLocation( );
  288.     ODNVMethod void            NotifyDragToTrash( ODULong );
  289.     ODNVMethod void            CloseTrashedDocument(ODDocument* document, DescType saveOptions );
  290.  
  291.     ODNVMethod ODBoolean    IsSessionModal();
  292.  
  293.     //-------------------------------------------------------------------------
  294.     // Update menus
  295.  
  296.     struct MenuItemInfo
  297.     {
  298.         Str255    text;
  299.         short    cmdChar;
  300.         short    iconID;
  301.         short    markChar;
  302.         Style    textStyle;
  303.     };
  304.  
  305.     ODNVMethod     void    CheckMenuBar();
  306.     ODNVMethod    void    UpdateMenus();
  307.     ODNVMethod    void    UpdateUndoMenus();
  308.     ODNVMethod    void    SaveMenuItem(MenuHandle menu, short itemNum,
  309.                                         MenuItemInfo* info);
  310.     ODNVMethod    void    RestoreMenuItem(MenuHandle menu, short itemNum,
  311.                                         MenuItemInfo* info);
  312.     ODNVMethod     void    ResetUndoText(MenuHandle editMenu);
  313.     ODNVMethod     void    ResetRedoText(MenuHandle editMenu);
  314.  
  315. //-------------------------------------------------------------------------------------
  316. // Memory Management
  317. //-------------------------------------------------------------------------------------
  318.  
  319.     ODNVMethod    void    InitMemory( );    
  320.  
  321.     ODNVMethod    ODSize    Purge(ODSize size);
  322.     
  323.     ODNVMethod    ODSize    IsFreeMemoryLow( ODBoolean &appIsLow, ODBoolean &tempIsLow );
  324.     
  325.     ODNVMethod    ODBoolean    CheckFreeMemory( );        // Returns false if low on memory
  326.     
  327.     ODNVMethod    void    LowMemoryAlert( ODBoolean tempMem );
  328.  
  329.     ODNVMethod    ODBoolean LowAppMemoryAlert( ODBoolean fatalLowMem );
  330.  
  331.     ODNVMethod    void     LowTempMemoryAlert(void);
  332.  
  333. //-------------------------------------------------------------------------------------
  334. // Shell User Functionality
  335. //-------------------------------------------------------------------------------------
  336.  
  337.     //-------------------------------------------------------------------------
  338.     // New (document)
  339.  
  340.     ODNVMethod PlatformFile* New();
  341.         // implements the menu command
  342.         // create a new document with the same part as the root part of the active window
  343.                 
  344.     //-------------------------------------------------------------------------
  345.     // Open (document)
  346.  
  347.     ODNVMethod ODDocument* OpenFile(PlatformFile* file,
  348.                                     ODBoolean forceOpenApp =kODFalse);
  349.     
  350.     ODNVMethod void OpenAnotherFile(PlatformFile* file,
  351.             AEDescList* replyInfo = kODNULL,
  352.             ODBoolean deleteOnFailure = kODFalse,
  353.             ODBoolean unsavedDoc = kODFalse);
  354.  
  355.     ODNVMethod void OpenStdFile();
  356.  
  357.     //-------------------------------------------------------------------------
  358.     // Close (window/document)
  359.  
  360.     ODNVMethod ODBoolean DoesUserCancelClose(ODDocument* document, DescType saveOptions);    
  361.     
  362.     //-------------------------------------------------------------------------
  363.     // Delete (document)
  364.  
  365.     ODNVMethod void DeleteDocument(ODDocument* document);    
  366.  
  367.     //-------------------------------------------------------------------------
  368.     // Save (document)
  369.  
  370.     ODNVMethod void ShowSaveDiffVolDialog( );
  371.     ODNVMethod void CloseSaveDiffVolDialog( );
  372.  
  373.  
  374.     ODNVMethod ODBoolean AskUserWhereToPutIt(
  375.                 ODDraft* whichDraft, Str255 defaultName, 
  376.                 Str255 msg, StandardFileReply* reply );
  377.  
  378.     ODNVMethod void SaveACopy(ODDraft* draft);        
  379.  
  380.     //-------------------------------------------------------------------------
  381.     // Revert (document)
  382.  
  383.     ODNVMethod    void    Revert(ODDocument* document);    
  384.  
  385.     ODNVMethod    ODBoolean    DoesUserOKRevert(ODDocument* document);    
  386.         
  387.     //-------------------------------------------------------------------------
  388.     // Drafts (of document)
  389.  
  390.     ODNVMethod    void        Drafts(ODDocument* document);    
  391.         
  392.     //-------------------------------------------------------------------------
  393.     // Info
  394.  
  395.     ODNVMethod    void        DocumentInfo(ODDocument* document);    
  396. //    ODNVMethod    void        PartInfo();    
  397.  
  398. //-------------------------------------------------------------------------------------
  399. // Error Handling & Notification
  400. //-------------------------------------------------------------------------------------
  401.  
  402.     ODNVMethod    void        ExceptionAlert(ODError exceptionCode, const char message[]);
  403.  
  404.     ODNVMethod    ODBoolean    SearchErrTable(    ODError value,
  405.                                             ODResNumber resourceID,
  406.                                             Str255 str);
  407.  
  408.     ODNVMethod    ODBoolean    LookupErrString(ODError value,
  409.                                                ODResNumber resourceID,
  410.                                                Str255 str);
  411.  
  412.     ODNVMethod    ODError    GetAEError();
  413.     
  414.     
  415.     // Pointer to notifier method which returns void and takes a refCon:
  416.     typedef    void (RealShell::*Notifier) ( ODULong refCon );
  417.     
  418.     ODNVMethod    void    Notify( RealShell::Notifier, ODULong refCon =0 );
  419.     
  420.     ODNVMethod    void    CancelNotification( RealShell::Notifier );
  421.     
  422.     ODNVMethod    void    ShowPendingNotifications( );
  423.  
  424.     ODNVMethod    void    LaunchFailed( ODSLong launchErr,
  425.                                     const ProcessSerialNumber &psn,
  426.                                     Str255 appName, Str255 libName );
  427.  
  428. //-------------------------------------------------------------------------------------
  429. // Apple Event Support
  430. //-------------------------------------------------------------------------------------
  431.  
  432.     ODNVMethod void InitAE();
  433.     
  434.     ODNVMethod void FakePrintMenuEvent();
  435.     
  436.     static pascal ODError HandleOpenAppEvent(ODPart*    thePart,
  437.                                             ODAppleEvent* message,
  438.                                             ODAppleEvent* reply,
  439.                                             ODSLong     refCon);
  440.                             
  441.     static pascal ODError HandleOpenPrintDocsEvent(    ODPart*    thePart,
  442.                                 ODAppleEvent* message,
  443.                                 ODAppleEvent* reply,
  444.                                 ODSLong     refCon);
  445.                                                                                             
  446.     static pascal ODError HandleQuitEvent(    ODPart*    thePart,
  447.                             ODAppleEvent* message,
  448.                             ODAppleEvent* reply,
  449.                             ODSLong     refCon);
  450.                                         
  451.     static pascal ODError HandleLaunchFailedEvent(    ODPart*    thePart,
  452.                             ODAppleEvent* message,
  453.                             ODAppleEvent* reply,
  454.                             ODSLong     refCon);
  455.                                         
  456.     static pascal ODError HandleDocSizeChangeInteraction( ODPart* thePart,
  457.                             ODAppleEvent* message,
  458.                             ODAppleEvent* reply,
  459.                             ODSLong       handlerRefcon);
  460.                                         
  461.     static pascal ODError HandleODActivate( ODPart* thePart, 
  462.                             ODAppleEvent* message,
  463.                             ODAppleEvent* reply,
  464.                             ODSLong handlerRefcon );
  465.         
  466.     static pascal ODError CoerceToFSSpec(ODPart* thePart,
  467.                                 ODDesc* theAEDesc,
  468.                                 DescType toType,
  469.                                 ODSLong handlerRefCon,
  470.                                 ODDesc* result);
  471.  
  472.  
  473. //-------------------------------------------------------------------------------------
  474. // Methods for handling changing the document size.
  475. //-------------------------------------------------------------------------------------
  476.  
  477.     ODNVMethod    ODBoolean    ChangeDocSize(FSSpec* theFSSpec, ODBoolean increaseSize, 
  478.                                         ODBoolean fatalLowMem);
  479.  
  480.     ODNVMethod    ODError     CloseAndReopenDoc(FSSpec* theFSSpec);
  481.  
  482.  
  483. //-------------------------------------------------------------------------------------
  484. // Utilities for setting/getting file names ($opt: can probably inline these)
  485. //-------------------------------------------------------------------------------------
  486.  
  487.     void            GetUserFileName(char* fileName, ODULong maxLen);
  488.  
  489. //-------------------------------------------------------------------------------------
  490. // Utilities to be moved to DocUtils
  491. //-------------------------------------------------------------------------------------
  492.  
  493.     ODNVMethod void CreateUniqueTmpFolderForFile(FSSpec* result,
  494.             Str63 fileName);
  495.  
  496.     ODNVMethod void    CreateUntitledContainer(ODDocument** documentPtr,
  497.             ODContainer** containerPtr, PlatformFile* newFile, ODName* fileNameSeed = kODNULL);
  498.         // *documentPtr, *containerPtr are filled in
  499.         // newFile is in/out
  500.  
  501.     ODNVMethod void    CreateTitledContainer(ODDocument** documentPtr,
  502.             ODContainer** containerPtr, PlatformFile* newFile, char* newName);
  503.         // *documentPtr, *containerPtr are filled in
  504.         // newFile is in/out
  505.  
  506.     ODNVMethod void GetCurrentProcessInfo( ProcessInfoRec *info,
  507.                             StringPtr name =kODNULL, FSSpec *appLoc =kODNULL );
  508.  
  509. //-------------------------------------------------------------------------------------
  510. // private fields
  511. //-------------------------------------------------------------------------------------
  512.  
  513.     //-------------------------------------------------------------
  514.     // session fields
  515.  
  516.     Environment*        fEV;
  517.     ODSession*             fSession;
  518.     ODDispatcher*         fDispatcher;
  519.     ODWindowState*        fWindowState;
  520.     ODArbitrator*        fArbitrator;
  521.     SIHelper*             fSIHelper;
  522.     short                fUniqueNameSeed;
  523.     ODTypeToken         fModalFocusToken;
  524.     
  525.     MenuItemInfo        fDefaultUndoMenuItem;
  526.     MenuItemInfo        fDefaultRedoMenuItem;
  527.     MenuItemInfo        fDefaultAboutMenuItem;
  528.     MenuItemInfo        fDefaultPrefsMenuItem;
  529.     
  530.     ODBoolean            fAPPLProcess;
  531.  
  532.     //-------------------------------------------------------------
  533.     // transitional state fields
  534.  
  535.     ODBoolean            fOptionKeyDownOnMenuBarClick;
  536.     ODBoolean            fShellHasMenuFocus;
  537.     ODBoolean            fAlreadyInCoercion;
  538.     ODError                fErrorFromOpenEvents;
  539.     ODBoolean            fProcessIsActive;
  540.     ODBoolean            fMouseButtonIsDown;
  541.  
  542.     ProcessSerialNumber    fLastNewDocPSN;
  543.     ODFileSpec            fLastNewDocSpec;
  544.     SaveCopyStruct*     fSaveCopyData;
  545.     DialogPtr            fSaveDiffVolDialog;
  546.     
  547.     //-------------------------------------------------------------
  548.     // error/notification fields
  549.  
  550.     ODBoolean            fLowTempMemNotified;
  551.     ODBoolean            fLowAppMemNotified;
  552.     ODBoolean            fOutOfTempMemNotified;
  553.     
  554.     Str63                fFailedPlugInName;
  555.     
  556.     LinkedList            fNotifiers;
  557.     
  558.     friend struct NotEntry;        // It has a Notifier as a member
  559. };
  560.  
  561.  
  562.  
  563. #endif    // _RLSHELL_
  564.